package com.supcalls.collections;

import java.util.Queue;
import java.util.concurrent.*;

public class ConcurrentLinkedQueueExample {
    public static void main(String[] args) {
        // 创建线程安全的 ConcurrentLinkedQueue
        Queue<Integer> queue = new ConcurrentLinkedQueue<>();

        // 创建多个线程操作该集合
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 1000; i++) {
                queue.offer(i);
            }
        });

        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 1000; i++) {
                queue.offer(i + 1000);
            }
        });

        t1.start();
        t2.start();

        try {
            t1.join();
            t2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("ConcurrentLinkedQueue size: " + queue.size());
    }
}
